package com.cskaoyan.controller.wxcontroller;

import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.StorageCreateVO;
import com.cskaoyan.service.SystemService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.UUID;

/**
 * @author: thz
 * @class: StorageController
 */
@RequestMapping("/wx/storage")
@RestController
public class StorageController {

    @Autowired
    SystemService systemService;

    @SneakyThrows
    @RequestMapping("upload")
    public BaseRespVo wxStorageUpload(MultipartFile file){
        File newFile = new File("D:\\spring\\image\\wx\\storage\\fetch\\" + UUID.randomUUID().toString() +
                file.getContentType().replace("image/","."));
        file.transferTo(newFile);
        StorageCreateVO storageCreateVO=systemService.addStorage(newFile,file);
        return BaseRespVo.ok(storageCreateVO);
    }

}
